package by.grsu.samusev.page.pages;



import org.apache.wicket.markup.html.WebPage;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.form.SubmitLink;
import org.apache.wicket.markup.html.form.TextField;
import org.apache.wicket.markup.html.link.Link;
import org.apache.wicket.model.CompoundPropertyModel;

import by.grsu.samusev.app.SamusevWebApplication;
import by.grsu.samusev.dao.impl.CarDao;
import by.grsu.samusev.entity.Car;




public class CarEditPage extends WebPage {

	public CarEditPage(final Car car) {
		super();


		final Form<Car> form = new Form<Car>("form", new CompoundPropertyModel<Car>(car));
		add(form);

		form.add(new TextField<Boolean>("Status"));	
		form.add(new TextField<String>("characteristic"));		

		form.add(new SubmitLink("save") {
			@Override
			public void onSubmit() {
				super.onSubmit();

				CarDao carDao = new CarDao(SamusevWebApplication.DATA_XML_FOLDER);
				if (car.getId() == null) {
					System.out.println("save="+car);
					carDao.saveNew(car);
				} else {
					System.out.println("update="+car);
					carDao.update(car);
				}

				setResponsePage(new CarListPage());
			}
		});

		form.add(new Link("cancel") {
			@Override
			public void onClick() {
				setResponsePage(new CarListPage());
			}
		});

	}
}
